-- ConfusedSlime
-- Created by chendh Dec/24/2016
-- 混乱的冈布奥

-- 初始化
function initConfusedSlime(self)
    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    local offsetY = tonumber(buildingInfo["icon_offset_y"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:setPositionY(self.icon:getPositionY() + offsetY);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;

    if self.gridData.need_shining == 1 then
        -- 闪光
        self.shiningAjustPos = cc.p(70, 100);
        shiningEffect(self.icon, self.shiningAjustPos.x, self.shiningAjustPos.y);
    end

    if self.gridData.need_animation == 1 then
        -- 呼吸
        self:doModelBreath(self.icon);
    end

    local function okFunc(index)
        local pos = self.gridData:getPos();

        -- 执行选项操作
        DungeonActionM.go("wake_up_confused_slime", pos, index);

        local dbase = DungeonM.queryElement(self.gridData.element, "dbase");
        -- 如果选错了，弹出提示
        if index ~= dbase["answer"] then
            alert(getLocStr("confuse_slime_fail"));
        end
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            if self.gridData.is_talked == 1 then
                alert(getLocStr("confuse_slime_talked"));
                return;
            end

            local textList = {
                getLocStr("confuse_slime_option1"),
                getLocStr("confuse_slime_option2"),
                getLocStr("confuse_slime_option3"), }
            local funcList = { okFunc, okFunc, okFunc, };

            self:openBuildingView5(funcList, textList);
        end
    end
    self.icon:addTouchEventListener(onClicked);
end
